package com.jack.lib.base

import androidx.appcompat.app.AppCompatActivity
import me.imid.swipebacklayout.lib.app.SwipeBackActivityBase
import me.imid.swipebacklayout.lib.app.SwipeBackActivityHelper
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import me.imid.swipebacklayout.lib.SwipeBackLayout
import me.imid.swipebacklayout.lib.Utils

/**
 * author : jack(黄冲)
 * e-mail : 907755845@qq.com
 * create : 2020/9/3
 * desc   :
 */
open class SwipeBackActivity : AppCompatActivity(), SwipeBackActivityBase {

    private var mHelper: SwipeBackActivityHelper? = null

    override fun onPostCreate(savedInstanceState: Bundle?) {
        super.onPostCreate(savedInstanceState)
        mHelper?.onPostCreate()
    }

    override fun <T : View?> findViewById(id: Int): T {
        val v = super.findViewById<View>(id)
        return if (v == null && mHelper != null) mHelper!!.findViewById(id) as T else v as T
    }

    override fun getSwipeBackLayout(): SwipeBackLayout {
        return mHelper!!.swipeBackLayout
    }

    override fun setSwipeBackEnable(enable: Boolean) {
        if (enable && mHelper == null) {
            mHelper = SwipeBackActivityHelper(this)
            mHelper!!.onActivityCreate()
        }
        if (mHelper != null) {
            swipeBackLayout.setEnableGesture(enable)
        }
    }

    override fun scrollToFinishActivity() {
        Utils.convertActivityToTranslucent(this)
        swipeBackLayout.scrollToFinishActivity()
    }
}